#ifndef __IJPEGD_H__
#define __IJPEGD_H__

#include <icommon.h>

#ifdef __cplusplus
extern "C" {
#endif

#define IJPEGD_VERSION	"1.0"
#define	IJPEGD_BUILD		"2015.1.1 - 2015.2.1"

typedef struct ijpegd ijpegd_t;

/****************************************************************************
 * NAL structure and functions
 ****************************************************************************/
/* The data within the payload is already NAL-encapsulated; the ref_idc and type
 * are merely in the struct for easy access by the calling application.
 * All data returned in an ijpegd_nal_t, including the data in p_payload, is no longer
 * valid after the next call to ijpegd_decoder_decode.  Thus it must be used or copied
 * before calling ijpegd_decoder_decode or ijpegd_decoder_headers again.
 */
typedef struct ijpegd_nal {
    int     i_payload;
    uint8_t *p_payload;
} ijpegd_nal_t;

typedef struct ijpegd_param {
	/* soc, buf, device manage */
	int			soc;
	int			b_tlb;
	int			b_use_phy;
	int			i_devid;

	/* Video Properties */
	int         i_csp;         /* CSP of decoded bitstream */
	int         i_max_width;
	int         i_max_height;

    /* Log */
    void        (*pf_log)(const char *module, int i_level, const char *psz, va_list);
    char        *module;
    int         i_log_level;

	/* buf managememt */
	/* must be vitural addr */
	void *(*ckmalloc)(int index, int size, int align);
	void (*ckfree)(int index, void *);
	intptr_t (*ckvirt_to_phys)(intptr_t vaddr);
	intptr_t (*ckphys_to_virt)(intptr_t paddr);
} ijpegd_param_t;

enum ijpegd_ql {
	IJPEGD_QL_AUTO		= -1,
	IJPEGD_QL_NORMAL		= 0,
	IJPEGD_QL_FINE		= 1,
	IJPEGD_QL_FINER		= 2,
};

typedef struct ijpegd_pic {
	intptr_t	virAddr;
	int			size;
	c_img_t		img;
} ijpegd_pic_t;

extern void ijpegd_param_default(ijpegd_param_t *param);
extern ijpegd_t *ijpegd_init(ijpegd_param_t *param);
extern int ijpegd_decode(ijpegd_t *h, ijpegd_pic_t *pic_out, ijpegd_nal_t *pnal_in);
extern void ijpegd_deinit(ijpegd_t *h);

#ifdef __cplusplus
}
#endif

#endif /* __IJPEGD_H__ */
